package edu.cuit.canary;

/**
 * 算术运算符
 */
public class ArithmeticOperator {
    public static void main(String[] args) {
        System.out.println(10  % 2); // 0
        System.out.println(10 % 4); // 2
        System.out.println(10 % -4); // 2
        System.out.println(-10 % -4);// -2
        System.out.println(-10 % 4); // -2
        int x = 3510;
        x = x / 1000 * 1000; //3000
        System.out.println(x);

        System.out.println("=========================");

        int count = 0;
        count += 10; //count = count + 10;

        byte number = 10;
        number = (byte)(number + 10); //10:int,类型的自动提升为int ===> 类型强转

        byte num = 10;
        num += 10;

        System.out.println("=========================");
        int count1 = 0;
        count1++; //count1 += 1;
        System.out.println(count1);

        /*
            前置++/--:先自身+1/-1然后参与运算
            后置++/--:先参与运算然后自身+1/-1
         */

        int x1 = 10;
        int y1 = x1++;
        System.out.println("x1 = " + x1); //11
        System.out.println("y1 = " + y1); //10

        int x2 = 10;
        int y2 = ++x2;
        System.out.println("x2 = " + x2); //11
        System.out.println("y2 = " + y2); //11

        /*
        初始化a=3，b=4；请计算：
            a++ / 3 + --b * 2 - a-- % 6 + b++ * 3 - b--
            a++ / 3: r = 1, a = 4   +
            --b * 2: r = 6, b = 3   -
            a-- % 6: r = 4, a = 3   +
            b++ * 3: r = 9, b = 4   -
            b--: r = 4, b = 3
            r = 8
         */
        int a = 3, b = 4;
        System.out.println(a++ / 3 + --b * 2 - a-- % 6 + b++ * 3 - b--);
        System.out.println("a = " + a + ", b = " + b);

        byte b2 = (byte)200;
        System.out.println(b2);
    }
}
